<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" class="formWidth" label-width="100px">
      <el-form-item label="现工作单位" prop="workUnit">
        <el-input
          v-model="queryParams.workUnit"
          placeholder="请输入现工作单位"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="现单位性质" prop="unitNature">
        <el-select v-model="queryParams.unitNature" placeholder="请选择现单位性质" clearable size="small">
          <el-option
            v-for="dict in unitNatureOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="个人年收入" prop="monthPension">
        <el-input
          v-model="queryParams.monthPension"
          placeholder="请输入个人年收入"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="医疗保险" prop="medicare">
        <el-select v-model="queryParams.medicare" placeholder="请选择医疗保险" clearable size="small">
          <el-option
            v-for="dict in medicareOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="养老保险" prop="endowmentInsurance">
        <el-select v-model="queryParams.endowmentInsurance" placeholder="请选择养老保险" clearable size="small">
          <el-option
            v-for="dict in endowmentInsuranceOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="住房公积金" prop="accumulationFund">
        <el-select v-model="queryParams.accumulationFund" placeholder="请选择住房公积金" clearable size="small">
          <el-option
            v-for="dict in accumulationFundOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="住房状况" prop="housingStatus">
        <el-select v-model="queryParams.housingStatus" placeholder="请选择住房状况" clearable size="small">
          <el-option
            v-for="dict in housingStatusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="社会救助状况" prop="socialAssistance">
        <el-select v-model="queryParams.socialAssistance" placeholder="请选择社会救助状况" clearable size="small">
          <el-option
            v-for="dict in socialAssistanceOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="享受国家抚恤补助金" prop="pensionGrant" label-width="160px">
        <el-select v-model="queryParams.pensionGrant" placeholder="请选择享受国家抚恤补助金" clearable size="small">
          <el-option
            v-for="dict in pensionGrantOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="享受残疾人两项补贴" prop="disabledSubsidy" label-width="160px">
        <el-select v-model="queryParams.disabledSubsidy" placeholder="请选择享受残疾人两项补贴" clearable size="small">
          <el-option
            v-for="dict in disabledSubsidyOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['archive_info:living_condition_info:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['archive_info:living_condition_info:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['archive_info:living_condition_info:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['archive_info:living_condition_info:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="living_condition_infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="享受残疾人两项补贴" align="center" prop="id" :show-overflow-tooltip="true" />
      <el-table-column label="现工作单位" align="center" prop="workUnit" :show-overflow-tooltip="true"/>
      <el-table-column label="现单位性质" align="center" prop="unitNature" :formatter="unitNatureFormat" :show-overflow-tooltip="true"/>
      <el-table-column label="个人年收入" align="center" prop="monthPension" :show-overflow-tooltip="true"/>
      <el-table-column label="医疗保险" align="center" prop="medicare" :formatter="medicareFormat" :show-overflow-tooltip="true"/>
      <el-table-column label="养老保险" align="center" prop="endowmentInsurance" :formatter="endowmentInsuranceFormat" :show-overflow-tooltip="true"/>
      <el-table-column label="住房公积金" align="center" prop="accumulationFund" :formatter="accumulationFundFormat" :show-overflow-tooltip="true"/>
      <el-table-column label="住房状况" align="center" prop="housingStatus" :formatter="housingStatusFormat" :show-overflow-tooltip="true"/>
      <el-table-column label="社会救助状况" align="center" prop="socialAssistance" :formatter="socialAssistanceFormat" :show-overflow-tooltip="true"/>
      <el-table-column label="享受国家抚恤补助金" align="center" prop="pensionGrant" :formatter="pensionGrantFormat" :show-overflow-tooltip="true"/>
      <el-table-column label="享受残疾人两项补贴" align="center" prop="disabledSubsidy" :formatter="disabledSubsidyFormat" :show-overflow-tooltip="true"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['archive_info:living_condition_info:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['archive_info:living_condition_info:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改生活状况模块对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="850px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" class="formWidth" label-width="150px">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="现工作单位" prop="workUnit">
              <el-input v-model="form.workUnit" placeholder="请输入现工作单位" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="现单位性质" prop="unitNature">
              <el-select v-model="form.unitNature" placeholder="请选择现单位性质">
                <el-option
                  v-for="dict in unitNatureOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="parseInt(dict.dictValue)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="个人年收入" prop="monthPension">
              <el-input v-model="form.monthPension" placeholder="请输入个人年收入" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="医疗保险" prop="medicare">
              <el-select v-model="form.medicare" placeholder="请选择医疗保险">
                <el-option
                  v-for="dict in medicareOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="parseInt(dict.dictValue)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row> 
        <el-row :gutter="20">
          <el-col :span="12">   
            <el-form-item label="养老保险" prop="endowmentInsurance">
              <el-select v-model="form.endowmentInsurance" placeholder="请选择养老保险">
                <el-option
                  v-for="dict in endowmentInsuranceOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="parseInt(dict.dictValue)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="住房公积金" prop="accumulationFund">
              <el-select v-model="form.accumulationFund" placeholder="请选择住房公积金">
                <el-option
                  v-for="dict in accumulationFundOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="parseInt(dict.dictValue)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">   
            <el-form-item label="住房状况" prop="housingStatus">
              <el-select v-model="form.housingStatus" placeholder="请选择住房状况">
                <el-option
                  v-for="dict in housingStatusOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="parseInt(dict.dictValue)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="自建房选择间数" prop="housingRoomCount">
              <el-input v-model="form.housingRoomCount" placeholder="请输入自建房选择间数" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">   
            <el-form-item label="建筑面积" prop="houseAcreage">
              <el-input v-model="form.houseAcreage" placeholder="请输入建筑面积" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="社会救助状况" prop="socialAssistance">
              <el-select v-model="form.socialAssistance" placeholder="请选择社会救助状况">
                <el-option
                  v-for="dict in socialAssistanceOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">   
            <el-form-item label="享受国家抚恤补助金" prop="pensionGrant">
              <el-select v-model="form.pensionGrant" placeholder="请选择享受国家抚恤补助金">
                <el-option
                  v-for="dict in pensionGrantOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="parseInt(dict.dictValue)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="享受残疾人两项补贴" prop="disabledSubsidy">
              <el-select v-model="form.disabledSubsidy" placeholder="请选择享受残疾人两项补贴">
                <el-option
                  v-for="dict in disabledSubsidyOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="parseInt(dict.dictValue)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>    
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listLiving_condition_info, getLiving_condition_info, delLiving_condition_info, addLiving_condition_info, updateLiving_condition_info, exportLiving_condition_info } from "@/api/archive_info/living_condition_info";

export default {
  name: "Living_condition_info",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 生活状况模块表格数据
      living_condition_infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 现单位性质字典
      unitNatureOptions: [],
      // 医疗保险字典
      medicareOptions: [],
      // 养老保险字典
      endowmentInsuranceOptions: [],
      // 住房公积金字典
      accumulationFundOptions: [],
      // 住房状况字典
      housingStatusOptions: [],
      // 社会救助状况字典
      socialAssistanceOptions: [],
      // 享受国家抚恤补助金情况字典
      pensionGrantOptions: [],
      // 享受残疾人两项补贴情况字典
      disabledSubsidyOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        workUnit: null,
        unitNature: null,
        monthPension: null,
        medicare: null,
        endowmentInsurance: null,
        accumulationFund: null,
        housingStatus: null,
        socialAssistance: null,
        pensionGrant: null,
        disabledSubsidy: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("unit_nature").then(response => {
      this.unitNatureOptions = response.data;
    });
    this.getDicts("medical_insurance").then(response => {
      this.medicareOptions = response.data;
    });
    this.getDicts("endowment_insurance").then(response => {
      this.endowmentInsuranceOptions = response.data;
    });
    this.getDicts("have_or_no").then(response => {
      this.accumulationFundOptions = response.data;
    });
    this.getDicts("house_property").then(response => {
      this.housingStatusOptions = response.data;
    });
    this.getDicts("social_assistance").then(response => {
      this.socialAssistanceOptions = response.data;
    });
    this.getDicts("yes_or_no").then(response => {
      this.pensionGrantOptions = response.data;
    });
    this.getDicts("yes_or_no").then(response => {
      this.disabledSubsidyOptions = response.data;
    });
  },
  methods: {
    /** 查询生活状况模块列表 */
    getList() {
      this.loading = true;
      listLiving_condition_info(this.queryParams).then(response => {
        this.living_condition_infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 现单位性质字典翻译
    unitNatureFormat(row, column) {
      return this.selectDictLabel(this.unitNatureOptions, row.unitNature);
    },
    // 医疗保险字典翻译
    medicareFormat(row, column) {
      return this.selectDictLabel(this.medicareOptions, row.medicare);
    },
    // 养老保险字典翻译
    endowmentInsuranceFormat(row, column) {
      return this.selectDictLabel(this.endowmentInsuranceOptions, row.endowmentInsurance);
    },
    // 住房公积金字典翻译
    accumulationFundFormat(row, column) {
      return this.selectDictLabel(this.accumulationFundOptions, row.accumulationFund);
    },
    // 住房状况字典翻译
    housingStatusFormat(row, column) {
      return this.selectDictLabel(this.housingStatusOptions, row.housingStatus);
    },
    // 社会救助状况字典翻译
    socialAssistanceFormat(row, column) {
      return this.selectDictLabel(this.socialAssistanceOptions, row.socialAssistance);
    },
    // 享受国家抚恤补助金情况字典翻译
    pensionGrantFormat(row, column) {
      return this.selectDictLabel(this.pensionGrantOptions, row.pensionGrant);
    },
    // 享受残疾人两项补贴情况字典翻译
    disabledSubsidyFormat(row, column) {
      return this.selectDictLabel(this.disabledSubsidyOptions, row.disabledSubsidy);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        workUnit: null,
        unitNature: null,
        monthPension: null,
        medicare: null,
        endowmentInsurance: null,
        accumulationFund: null,
        housingStatus: null,
        housingRoomCount: null,
        houseAcreage: null,
        socialAssistance: null,
        pensionGrant: null,
        disabledSubsidy: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加生活状况模块";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getLiving_condition_info(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改生活状况模块";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateLiving_condition_info(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addLiving_condition_info(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除生活状况模块编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delLiving_condition_info(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有生活状况模块数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportLiving_condition_info(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
